package com.hwtx.form.domain.chart;

/**
 * 展示如何使用EChartsLineChartOptions和EChartsLineChartBuilder
 * 创建折线图配置的示例。
 */
public class EChartsLineChartExample {

    /**
     * 使用构建器模式创建一个简单的折线图配置
     *
     * @return 配置好的图表选项
     */
    public static EChartsLineChartOptions createSimpleLineChart() {
        return EChartsLineChartBuilder.createWithTitle("网站流量")
                .withSubtitle("每日访客数量")
                .withTitlePosition("center", "top")
                .withLegend("访客数")
                .withLegendPosition("left", "top")
                .withTooltip("axis")
                .withXAxis("category", "周一", "周二", "周三", "周四", "周五", "周六", "周日")
                .withYAxis("value")
                .withAxisNames("星期", "访客数")
                .withGrid("3%", "4%", "20%", "3%", true)
                .addLineSeries("访客数", 120, 132, 101, 134, 90, 230, 210)
                .withSmoothLines()
                .build();
    }

    /**
     * 创建一个多系列的折线图（包含面积图）
     *
     * @return 配置好的图表选项
     */
    public static EChartsLineChartOptions createMultiSeriesChart() {
        return EChartsLineChartBuilder.createWithTitle("销售报告")
                .withSubtitle("各产品季度销售额")
                .withLegend("产品A", "产品B", "产品C")
                .withTooltip("axis")
                .withXAxis("category", "第一季度", "第二季度", "第三季度", "第四季度")
                .withYAxis("value")
                .withAxisNames("季度", "销售额（千元）")
                .addLineSeries("产品A", 120, 132, 101, 134)
                .addLineSeries("产品B", 220, 182, 191, 234)
                .addAreaSeries("产品C", 150, 232, 201, 154)
                .withoutSymbols()
                .build();
    }

    /**
     * 创建一个带有自定义样式的图表
     *
     * @return 配置好的图表选项
     */
    public static EChartsLineChartOptions createStyledChart() {
        EChartsLineChartOptions chart = EChartsLineChartBuilder.createWithTitle("性能指标")
                .withLegend("CPU", "内存")
                .withTooltip("axis")
                .withXAxis("category", "00:00", "04:00", "08:00", "12:00", "16:00", "20:00", "24:00")
                .withYAxis("value")
                .addLineSeries("CPU", 20, 32, 18, 45, 30, 25, 35)
                .addLineSeries("内存", 40, 52, 48, 65, 50, 45, 55)
                .build();

        // 自定义线条样式
        EChartsLineChartOptions.Series[] series = chart.getSeries();
        if (series != null && series.length > 0) {
            // 第一个系列的样式 (CPU)
            EChartsLineChartOptions.LineStyle cpuLineStyle = new EChartsLineChartOptions.LineStyle();
            cpuLineStyle.setColor("#5470C6");
            cpuLineStyle.setWidth(3);
            series[0].setLineStyle(cpuLineStyle);

            // 第二个系列的样式 (内存)
            EChartsLineChartOptions.LineStyle memoryLineStyle = new EChartsLineChartOptions.LineStyle();
            memoryLineStyle.setColor("#91CC75");
            memoryLineStyle.setWidth(2);
            series[1].setLineStyle(memoryLineStyle);
        }

        return chart;
    }
}